"""

@Time: 2021/9/13 9:14
@Author:
@File: vol_controller.py
"""
from fastapi import APIRouter, Depends, Body
from pydantic import Field
from models.dto.vol_dto import VolList, Province, Volunteer, VolQueryCond
from models.dto import RESTfulModel
from motor.motor_asyncio import AsyncIOMotorDatabase
from dependencies import get_mongo_db, verify_token
from service import ProvinceService, VolService
from typing import List

vol_router = APIRouter(tags=['volunteer'])




@vol_router.get('/province_list',
                response_model=RESTfulModel[List[Province]])
async def get_provinces(province_service: ProvinceService = Depends()):
    provinces = province_service.get_provinces()
    provinces = [Province(id=p.id, name=p.name) for p in provinces]
    return RESTfulModel(code=0,
                        data=provinces,
                        msg='')

@vol_router.post('/cond_query',
                response_model=RESTfulModel[List[Volunteer]])
async def query_volunteer(cond: VolQueryCond = Body(..., title='查询条件'),
                          vol_service: VolService = Depends()):
    volunteers = vol_service.query_volunteer(cond)
    return RESTfulModel(code=0,
                        data=volunteers)




async def add_vol(vol_list: VolList,
                  username: Depends(verify_token),
                  mongo: AsyncIOMotorDatabase = Depends(get_mongo_db),):
    pass

